package main

import (
	"fmt"
	"time"
)

//管道,解决协程中的异常
func main() {
	go sayHello()
	go sayOK()

	for i := 0; i < 10; i++ {
		fmt.Println("main() ok=", i)
		time.Sleep(time.Second)
	}
}

//函数
func sayHello() {
	for i := 0; i < 10; i++ {
		time.Sleep(time.Second)
		fmt.Println("hello,world")
	}
}

//函数
func sayOK() {
	var m map[int]string
	m[0] = "hello"

	//可以使用 defer + recover 处理异常
	defer func() {
		if err := recover(); err != nil {
			fmt.Println("发生错误")
		}
	}()
}
